<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class c_settings extends CI_Controller {

	function __construct(){
		parent::__construct();	
		checkLogin();
		$this->load->model('m_settings');
	}
	
	function index(){
		$task = $this->input->post("task");
		switch($task){
			case 'UBAH_PASSWORD' : 
				$this->ubah_password(); 
				break;
			case 'UPDATE' : 
				$this->update(); 
				break;
			default : 
			$data = $this->m_settings->data_user($_SESSION[SESSION_USERID]);
			$this->load->view('v_settings',$data);
		}
	}
	
	function ubah_password(){
		$data = array(
			"user_passwd" => md5($this->input->post("password"))
		);
		$this->m_settings->ubah_password($data,$_SESSION[SESSION_USERID]);
	}
	
	function update(){
		$data = array(
			"user_name" =>  ($this->input->post("user_name")),
			"user_real_name" =>  ($this->input->post("user_real_name")),
			"user_email" =>  ($this->input->post("user_email"))
		);
		$this->m_settings->ubah_password($data,$_SESSION[SESSION_USERID]);
	}
}